<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新漫监控平台</title>
    <link rel="shortcut icon" href="images/logo1.ico"/>
    <link rel="stylesheet" href="css/layout.css">
    <script src="js/jquery.js"></script>
    <script src="js/layer/layer.js"></script>
    <script src="js/common.js"></script>
    <script src="js/index.js"></script>
</head>
<body>
<img src="images/bg1.jpg" class="bgimg" alt="">
<div class="contentbox contentboxInterface">
    <div class="title">
        <span>后台管理界面</span>
        <span>|</span>
        <span class="small-title">SIMMAX</span>
        <div class="avatar-box">
            <img src="images/bg.jpg" class="avatar" alt="">
            <span class="ava-name">LIULISHEJUZHE</span>
        </div>
        <div class="setting-box">
            <a href="#">
                <img src="images/back.png" alt="">
                退出
            </a>
        </div>
    </div>
    <ul class="menu-box">
        <li class="menu1 ">
            <a href="interface.html">连接设备</a>
        </li>
        <li class="menu2">
            <a href="index.html">实时监控</a>
        </li>
        <li class="menu6">
            <a href="dataManager.html">数据管理</a>
        </li>
        <li class="menu3 active">
            <a href="Parameters.html">参数设置</a>
        </li>
        <li class="menu4 ">
            <a href="user.html">用户管理</a>
        </li>
        <li class="menu5">
            <a href="#">帮助</a>
        </li>
        <li class="menu7">
            <a href="systemLog.html">日志管理</a>
        </li>
    </ul>
    <div class="paramentersDiv ">
        <img src="images/Parameters.png" alt="">
        <div class="paramenthreshold">

        </div>
    </div>
</div>
</body>
<script>
    function paranerterTime(){
        $.ajax({
            type:"get",
            url: apiDomain +paramentersConfigList,
            xhrFields: {
                withCredentials: true
            },
            crossDomain:true,
            success: function (data) {
                console.log(data);
                var data = data.data.list;
                $(".paramenthreshold").append("<div class='middlethreshold thresholdDiv'>" +
                    "<span>中剂量阈值：</span>" +
                    "<div class='threshold_middle1'>" +
                    "<input type='hidden' class='warning_threshold_middle' value=" + data[1].name + ">" +
                    "<span>" + data[1].value + "</span>" +
                    "<img src='images/editor27.png' onclick='middlethreshold(this)'></div>" +
                    "<div class='threshold_middle2'>" +
                    "<input type='hidden' class='warning_threshold_middle' value=" + data[1].name + ">" +
                    "<input class='threshold_middleValue' type='text' value=" + data[1].value + ">" +
                    "<span onclick='MiddleTime(this)'>确认</span></div></div>");

                $(".paramenthreshold").append("<div class='goldthreshold thresholdDiv'>" +
                    "<span>高剂量阈值：</span>" +
                    "<div class='threshold_middle1'>" +
                    "<input type='hidden' class='warning_threshold_middle' value=" + data[2].name + ">" +
                    "<span>" + data[2].value + "</span>" +
                    "<img src='images/editor27.png' onclick='middlethreshold(this)'></div>" +
                    "<div class='threshold_middle2'>" +
                    "<input type='hidden' class='warning_threshold_middle' value=" + data[2].name + ">" +
                    "<input class='threshold_middleValue' type='text' value=" + data[2].value + ">" +
                    "<span onclick='MiddleTime(this)'>确认</span></div></div>");

                $(".paramenthreshold").append("<div class='warningthreshold thresholdDiv'>" +
                    "<span>报警阈值：</span>" +
                    "<div class='threshold_middle1'>" +
                    "<input type='hidden' class='warning_threshold_middle' value=" + data[3].name + ">" +
                    "<span>" + data[3].value + "</span>" +
                    "<img src='images/editor27.png' onclick='middlethreshold(this)'></div>" +
                    "<div class='threshold_middle2'>" +
                    "<input type='hidden' class='warning_threshold_middle' value=" + data[3].name + ">" +
                    "<input class='threshold_middleValue' type='text' value=" + data[3].value + ">" +
                    "<span onclick='MiddleTime(this)'>确认</span></div></div>");
                $(".paramenthreshold").append("<div class='neverthreshold thresholdDiv'>" +
                    "<span>无响应时间：</span><div class='threshold_middle1'>" +
                    "<input type='hidden' class='warning_threshold_middle' value=" + data[0].name + ">" +
                    "<span>" + data[0].value + "</span>s" +
                    "<img src='images/editor27.png' onclick='middlethreshold(this)'></div>" +
                    "<div class='threshold_middle2'>" +
                    "<input type='hidden' class='warning_threshold_middle' value=" + data[0].name + ">" +
                    "<input class='threshold_middleValue' type='text' value=" + data[0].value + ">" +
                    "<span onclick='MiddleTime(this)'>确认</span></div></div>");
            }
        })
    }
    paranerterTime();
    function middlethreshold(e){
            var _this=$(e);
            _this.parents('.threshold_middle1').next('.threshold_middle2').css('display','inline');
            _this.parents('.threshold_middle1').hide();
    }
    function MiddleTime(e){
        var _this=$(e);
        var spanHtmls=_this.parents('.thresholdDiv').children('span').html();
       var name= _this.parents('.threshold_middle2').find('.warning_threshold_middle').val();
       var value= _this.parents('.threshold_middle2').find('.threshold_middleValue').val();
       _this.parents('.threshold_middle2').prev('.threshold_middle1').find('span').html(value);

       if(spanHtmls=='中剂量阈值：'){
           var goldthresholdValue=Number($('.goldthreshold .threshold_middle1 span').html());
           if(goldthresholdValue>value){
               $.ajax({
                   type:"post",
                   url: apiDomain + paramentersUpdate,
                   data:{
                       name:name,
                       value:value
                   },
                   xhrFields: {
                       withCredentials: true
                   },
                   crossDomain:true,
                   success: function (data) {
                       layer.msg('修改成功');
                       _this.parents('.threshold_middle2').hide();
                       _this.parents('.threshold_middle2').prev('.threshold_middle1').show();
                   },
                   fail:function(){
                       layer.msg('修改失败，请重试');
                   }
               })
           }else{
               layer.msg('中剂量阈值要小于高剂量阈值');
           }
       }
       if(spanHtmls=='高剂量阈值：') {
           var middlethresholdVlaue = Number($('.middlethreshold .threshold_middle1 span').html());
           var warningthresholdValue = Number($('.warningthreshold .threshold_middle1 span').html());
            if(middlethresholdVlaue>=value){
                layer.msg('高剂量阈值要大于中剂量阈值');
            }else if(value>=warningthresholdValue){
                layer.msg('高剂量阈值要小于报警阈值');
            }else{
                $.ajax({
                    type:"post",
                    url: apiDomain + paramentersUpdate,
                    data:{
                        name:name,
                        value:value
                    },
                    xhrFields: {
                        withCredentials: true
                    },
                    crossDomain:true,
                    success: function (data) {
                        layer.msg('修改成功');
                        _this.parents('.threshold_middle2').hide();
                        _this.parents('.threshold_middle2').prev('.threshold_middle1').show();
                    },
                    fail:function(){
                        layer.msg('修改失败，请重试');
                    }
                })
            }

       }
        if(spanHtmls=='报警阈值：'){
            var goldthresholdVlaue = Number($('.goldthreshold .threshold_middle1 span').html());
            if(value>goldthresholdVlaue){
                $.ajax({
                    type:"post",
                    url: apiDomain + paramentersUpdate,
                    data:{
                        name:name,
                        value:value
                    },
                    xhrFields: {
                        withCredentials: true
                    },
                    crossDomain:true,
                    success: function (data) {
                        layer.msg('修改成功');
                        _this.parents('.threshold_middle2').hide();
                        _this.parents('.threshold_middle2').prev('.threshold_middle1').show();
                    },
                    fail:function(){
                        layer.msg('修改失败，请重试');
                    }
                })
            }else{
                layer.msg('报警阈值要大于高剂量阈值');
            }

        }
        if(spanHtmls=='无响应时间：'){
            $.ajax({
                type:"post",
                url: apiDomain + paramentersUpdate,
                data:{
                    name:name,
                    value:value
                },
                xhrFields: {
                    withCredentials: true
                },
                crossDomain:true,
                success: function (data) {
                    layer.msg('修改成功');
                    _this.parents('.threshold_middle2').hide();
                    _this.parents('.threshold_middle2').prev('.threshold_middle1').show();
                },
                fail:function(){
                    layer.msg('修改失败，请重试');
                }
            })
        }
    };
</script>
</html>